export default class DataTimeFormat{

    /**
     * 格式化时间: HH:mm:ss.SSS
     */
    public static timeFormat = (date: Date): string => {
        const hour = date.getHours();
        const minute = date.getMinutes();
        const second = date.getSeconds();
        const millisecond = date.getMilliseconds();
        return (hour + "").padStart(2,"0")
            + ":"
            + (minute + "").padStart(2, "0")
            + ":"
            + (second + "").padStart(2, "0")
            + "."
            + (millisecond + "").padStart(3, "0");
    }
    /**
     * 日期格式化: yyyy-MM-dd
     */
    public static dateFormat =(date: Date): string => {
        const year = date.getFullYear();
        const month = date.getMonth() + 1;
        const day = date.getDate();
        return year
            + "-"
            + (month + "").padStart(2, "0")
            + "-"
            + (day + "").padStart(2, "0");
    }

    /**
     * 日期时间格式化
     * @param date
     */
    public static dateTimeFormat = (date: Date): string => {
        return DataTimeFormat.dateFormat(date) + " " + DataTimeFormat.timeFormat(date);
    }
}